package com.caul.demo.hadoop.mapreduce.attention;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by sdliang on 2018/4/8.
 */
public class BothAttentionReducer extends Reducer<BothAttentKey, IntWritable, BothAttentKey, Text> {

  private Text textValue;

  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    textValue = new Text("attention to each other");
  }

  @Override
  protected void reduce(BothAttentKey key, Iterable<IntWritable> values, Context context)
      throws IOException, InterruptedException {
    int count = 0;
    for (IntWritable value : values) {
      count += value.get();
    }
    if (count > 1) {
      context.write(key, textValue);
    }
  }
}
